import java.io.IOException;
import java.io.BufferedReader;

public class ServerListener extends Thread {

	final private BufferedReader fromServer;
	private Boolean human; // Human or AI
	
	public ServerListener(BufferedReader fromServer, Boolean human) {
		this.fromServer = fromServer;
		this.human = human;
	}
	public void run() {
		String lineFromServer;
		if(human){
			try {
				while ((lineFromServer = fromServer.readLine()) != null && !lineFromServer.equals("quit")) {

					System.out.println("serverListener: " + lineFromServer); 
					GameClient.TalkToServer(lineFromServer); // Sends information back to player. Function TalkToServer
				}
			}
			catch (IOException | InterruptedException e) {}
		}
		else {
			try {
				while ((lineFromServer = fromServer.readLine()) != null && !lineFromServer.equals("quit")) {

					System.out.println("serverListener: " + lineFromServer); 
					GameAI.TalkToServer(lineFromServer); // Sends information back to AI. Function TalkToServer
				}
			}
			catch (IOException | InterruptedException e) {}
		}
	} //run
} //class ServerListener
